import { Inject, Provide } from '@midwayjs/core';

import { MyLoginDTO } from '../types/my/user.my.type';
import { UserRepository } from '../../infrastructure/persistence/user.persistence';


@Provide()
export class UserService {

  @Inject()
  userRepository: UserRepository;

  /**
   *
   * @param param login info
   */
  async login({ username, password }: MyLoginDTO) {
    const user = await this.userRepository.findByUsername(username);
    if (user == null) {
      throw new Error('用户名或密码错误');
    }

    if (user.password !== password) {
      throw new Error('用户名或密码错误');
    }

  }


}
